<?php
namespace Admin\Controller;
use Think\Controller;

class CommentController extends Controller{
    //分配登录模板
    public function index(){
        $this->url="/view/2017/10/";
        $this->page_title="ئىنكاس باشقۇرۇش";
        $comments=M('comment')
            ->join("dp_article ON dp_comment.newsid=dp_article.id")
            ->field("
            dp_article.title,
            dp_comment.id as cid,
            dp_comment.newsid,
            dp_comment.isim,
            dp_comment.ip
            ,dp_comment.content
            ,dp_comment.face,
            dp_comment.status,
            dp_comment.intime,
            dp_comment.nolisit
            ")
            ->where("nolisit='no'")
            ->select();
        if($comments){
            $this->comment_count=count($comments);
        }
        $this->assign('comments',$comments);
        $this->display("index");
    }
    //用ajax删除分类
    public function del(){
        $id=I('post.id');
        //获取要编辑的一条数据
        $data=M("comment")->delete($id);
        if(!$data){
            $data=array("status"=>0,"message"=>"ئۆچۈرۈش مەغلۇب بولدى ، قايتا سىناڭ !");
        }else{
            $data=array("status"=>1,"message"=>"ئۆچۈرۈش مۇۋاپىقيەتلىك بولدى !",'id'=>$id);
        };
        $this->ajaxReturn($data);
    }
    //用ajax分类状态
    public function sortStatus(){
        $id=I('post.id');
        $post['status']=I('post.status');
        $post['nolisit']="ok";
        if(!M('comment')->where("id='$id'")->save($post)){
            $data=array("status"=>0,"content"=>"مەغلۇب بولدى ، قايتا سىناڭ !");
        }else{
            $data=array("status"=>1,"content"=>" تەستىقلاندى !");
        }
        $this->ajaxReturn($data);
    }
    //用ajax排序分类
    public function save1(){
        $post=array();
        $id=I('post.id');
        $post['content']=I('post.content');
        //获取要编辑的一条数据
        $data=M("comment")->where("id='$id'")->save($post);
        if(!$data){
            $data=array("status"=>0,"message"=>"تەھرىرلەش مەغلۇب بولدى ، قايتا سىناڭ !");
        }else{
            $data=array("status"=>1,"message"=>"تەھرىرلەش مۇۋاپىقيەتلىك بولدى !");
        };
        $this->ajaxReturn($data);
    }
}